/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.enricod.jcontextfree.engine.samples.impl;

import com.google.inject.Inject;
import it.enricod.jcontextfree.engine.IProgramLoader;
import it.enricod.jcontextfree.engine.samples.IProgramCatalogEntry;
import it.enricod.jcontextfree.engine.samples.IProgramsCatalog;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author edonelli
 */
public class ClasspathProgramsCatalog implements IProgramsCatalog {

    private static final String BASE_PACKAGE = "it/enricod/jcontextfree/engine/samples";
    private Map<String, IProgramCatalogEntry> samples = new HashMap<String, IProgramCatalogEntry>();

    private IProgramLoader programLoader;
    

    @Inject
    public ClasspathProgramsCatalog(IProgramLoader programLoader) {
        this.programLoader = programLoader;

        samples.put("DEMO1", createProgramCatalogEntry("DEMO1", BASE_PACKAGE + "/demo1.cfdg", programLoader));
        samples.put("DEMO2", createProgramCatalogEntry("DEMO2", BASE_PACKAGE + "/demo2.cfdg", programLoader));
        samples.put("DEMO3", createProgramCatalogEntry("DEMO3", BASE_PACKAGE + "/demo3.cfdg", programLoader));
        samples.put("DEMO4", createProgramCatalogEntry("DEMO3", BASE_PACKAGE + "/demo4.cfdg", programLoader));
        samples.put("WELCOME", createProgramCatalogEntry("WELCOME", BASE_PACKAGE + "/welcome.cfdg", programLoader));
    }
    
    public Collection<IProgramCatalogEntry> getEntries() {
        return samples.values();
    }

    public IProgramCatalogEntry getEntry(String entryName) {
        if ( samples.get(entryName) == null ) {
            throw new IllegalArgumentException("ID programma non esistente: " + entryName);
        }
        return samples.get(entryName);
    }

    public IProgramCatalogEntry createProgramCatalogEntry(String id, String path, IProgramLoader programLoader) {
        return new ProgramCatalogEntry(id, path, programLoader);
    }
}
